package com.frogs.ucenter.service.daoimpl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.frogs.framework.base.dao.BaseDao;
import com.frogs.framework.base.service.daoimpl.BaseServiceImpl;
import com.frogs.ucenter.dao.AreaInfoDao;
import com.frogs.ucenter.entity.AreaInfo;
import com.frogs.ucenter.service.AreaInfoService;

@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
@Service("areaInfoService")
public class AreaInfoServiceImpl extends BaseServiceImpl<AreaInfo> implements
		AreaInfoService {

	@Resource
	private AreaInfoDao areaInfoDao;
	
	
	
	public AreaInfoServiceImpl() {
		super();
	}

	public AreaInfoDao getAreaInfoDao() {
		return areaInfoDao;
	}

	/**
	 * Don't remove or edit it.
	 */
	@Override
	protected BaseDao<AreaInfo> getBaseDao() {
		return areaInfoDao;
	}

	public void setAreaInfoDao(AreaInfoDao areaInfoDao) {
		this.areaInfoDao = areaInfoDao;
	}

	@Override
	public List<Map<String, String>> getSubAreaList(String parentId) throws Exception {
		try {
			return areaInfoDao.getSubAreaList(parentId);
		} catch (Exception e) {
			log.error("func[getSubAreaList] parentId[" + parentId + "] error[" + e.getMessage() + "]", e);
			return null;
		}
	}

	public List<String> getPostCode(String areaCode, String address) throws Exception {
		try {
			List<String> postCodeList = areaInfoDao.getPostCode(address,
					areaCode);
			return postCodeList;
		} catch (Exception e) {
			log.error(
					"func[getPostCode] params[" + areaCode + "," +  address + "] error["
							+ e.getMessage() + "]", e);
			return null;
		}
	}

	@Override
	public AreaInfo showArea(String province, String city, String district) throws Exception {
		return areaInfoDao.showArea(province,city, district);
	}
}